//
//  WSMainController.swift
//  WSWeiBo01
//
//  Created by 李维顺 on 16/7/10.
//  Copyright © 2016年 liweishun. All rights reserved.
//

import UIKit




class WSMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        let wsTabBar = WSTabBar()
//        self.tabBar = wsTabBar    系统tabBar是只读的
        //使用kvc赋值
        //设置代理
        wsTabBar.wsDelegate = self
        
        wsTabBar.buttonClosure = {[weak self] in
            print("闭包调用的")
        }
        
        setValue(wsTabBar, forKey: "tabBar")
        
        addChildViewController(WSHomeController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(WSMessageController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(WSDIscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(WSProfileController(), title: "我的", imgName: "tabbar_profile")
        

    }

    
     func addChildViewController(childController: UIViewController, title: String, imgName: String) {
        //添加标题
        childController.title = title
        //添加图片
        childController.tabBarItem.image = UIImage(named: imgName)
        //设置选中图片和图片的渲染颜色
        childController.tabBarItem.selectedImage = UIImage(named: imgName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字的颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        //设置文字的大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
        //设置子视图控制器
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
        
    }
    
    
    
    
    
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

 

}



extension WSMainController: WSTabBarDelegate {
    func didSelectedButton() {
        print("代理调用")
    }
}











